﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json.Linq;
using SysFrame.BP;
using SysFrame.Message;

namespace AppServer.Controllers.System
{
    [Route("api/[controller]")]
    [ApiController]
    public class System6Controller : SysControllerBase
    {
        //菜单
        // POST: api/System6
        [HttpPost]
        public ActionResult<string> Post([FromBody] dynamic data)
        {
            string jsTimeStamp = data.jsTimeStamp;
            string Action = data.Action==null?"Get": data.Action;
            string rtstr = "";
            //得到列表
            if (Action == "Get")
            {
                rtstr = Get(data);
            }
            if (Action == "GetSystem8")
            {
                rtstr = GetSystem8(data);
            }
            if (Action == "Save")
            {
                rtstr = Save(data);
            }
            return rtstr;
        }

        /// <summary>
        /// 得到菜单列表
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        public string Get(dynamic data)
        {
            BLLsystem_6 bll = new BLLsystem_6();
            List<Mssystem_6> mssys6 = new List<Mssystem_6>();
            Mssystem_1 mssys1 = new Mssystem_1();
            MsQuery msq = new MsQuery();
            msq.strquery += " and 1=1 and SYSTEM_6_30='1' ";
            mssys6 = bll.Getsystem_6MsByQuery(msq);
            return JArray.FromObject(mssys6).ToString();
        }

        /// <summary>
        /// 得到功能按钮
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        public string GetSystem8(dynamic data) {
            MsQuery ms = new MsQuery();
            JObject postdata = JObject.FromObject(data.data);
            string nodeId = postdata["nodeId"].ToString();
            //条件
            if (true)
            {
                ms.strquery += " and 1=1 and (SYSTEM_8_50='1' or SYSTEM_8_50 is null) ";
            }
            ms.strquery += " and SYSTEM_8_40='" + nodeId + "'";
            ms.strorder = " SYSTEM_8_60 ";//排序语句
            //List<Mssystem_8> listms = new BLLsystem_8().Getsystem_8MsByQuery(ms);
            DataTable dt = ((DataSet)new BLLsystem_8().Getsystem_8ByQuery(ms).data).Tables[0];
            return JArray.FromObject(dt).ToString();
        }

        /// <summary>
        /// 保存
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        public string Save(dynamic data)
        {
            JObject postdata = JObject.FromObject(data.data);
            Mssystem_6 ms6 = Mssystem_6.parse<Mssystem_6>(postdata);
            ms6.System_6_30 = "1";
            ms6.System_6_50 = "1";
            ms6.System_6_100 = "0";
            MsReturned rt = new BLLsystem_6().Savesystem_6(ms6);
            return JObject.FromObject(rt).ToString();
        }
    }
}
